package qimao.com.edu.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.fasterxml.jackson.databind.ObjectMapper;

import qimao.com.edu.entity.Users;
import qimao.com.edu.service.UsersService;
import qimao.com.edu.service.impl.UsersServiceImpl;

@WebServlet("/login.do")
public class LoginAdminServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		UsersService us = new UsersServiceImpl();
		HttpSession session = req.getSession();
		req.setCharacterEncoding("utf-8");
		String username=req.getParameter("username");
		String password=req.getParameter("password");
		// System.out.println(username+"_____"+password);
		Map<String,Object> map = us.userLogin(username, password);
		if(map.get("loginUser")!=null){
			session.setAttribute("loginUser", map.get("loginUser"));
			session.setMaxInactiveInterval(30 * 30 * 60);
			resp.sendRedirect("index.html");
		}else{
			req.setAttribute("msg",map.get("msg"));
			req.getRequestDispatcher("login-admin.html").forward(req,resp);
		}
	}
}
